import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ssm.mapper.UserMapper;
import ssm.myPojo.PerCustom;
import ssm.myPojo.PubCustom;
import ssm.myPojo.SourQueryVo;
import ssm.pojo.Pub;
import ssm.pojo.User;
import ssm.service.UserService;
import ssm.service.impl.UserServiceImpl;

import java.io.File;
import java.util.List;


public class test_base extends UserServiceImpl {

    @Autowired
    private UserService userService;

    private ApplicationContext applicationContext;

    @Before
    public void setUp()throws Exception{

        applicationContext = new ClassPathXmlApplicationContext("classpath:spring/ApplicationContext*.xml");

    }
    //测试通过姓名查找用户
    @Test
    public void testFindUserByName()throws Exception{

//        List<User> user = userService.findUserByName("zmy");
//
//        System.out.println(user);

//        UserMapper userMapper = (UserMapper) applicationContext.getBean("userMapper");
//
//        List<User> user = userMapper.selectByName("");
//
//        System.out.println(user);

        UserMapper userMapper = (UserMapper) applicationContext.getBean("userMapper");

        User user = new User();
        //user.setName("test1");
        user.setPwd("123456");
        userMapper.insert(user);
    }
    //删除测试
    @Test
    public void testDeleteByPrimaryKey(){

        UserMapper userMapper = (UserMapper) applicationContext.getBean("userMapper");

        userMapper.deleteByPrimaryKey(2);

    }
    //获取dao
    @Test
    public void getBean(){
        UserMapper userMapper = (UserMapper) applicationContext.getBean("userMapper");
        System.out.println(userMapper);

    }
    //测试通过LIKE查找资源
    @Test
    public void getResourByLike()throws Exception{

        UserService userService = (UserService) applicationContext.getBean("userService");

        SourQueryVo sourQueryVo  = new SourQueryVo();

        PubCustom pubCustom = new PubCustom();

        pubCustom.setSourcead("java");

        sourQueryVo.setPubCustom(pubCustom);

        List<PubCustom> list = userService.findAllPubByLike(sourQueryVo);

        System.out.println(list);
    }

    //测试数据插入到pub
    @Test
    public void testInsertIntoPub()throws Exception{

        UserService userService = (UserService) applicationContext.getBean("userService");

        PubCustom pubCustom = new PubCustom();

        pubCustom.setId(10);
        pubCustom.setResource("test");
        pubCustom.setSourcetype("test");
        pubCustom.setSourcead("test");
        pubCustom.setSourcenote("test");

       userService.insertIntoPub(pubCustom);
    }

    //测试数据插入到per
    @Test
    public void testInsertIntoPer()throws Exception{

        UserService userService = (UserService) applicationContext.getBean("userService");

        PerCustom perCustom = new PerCustom();

        perCustom.setId(10);
        perCustom.setResource("test");
        perCustom.setSourcetype("test");
        perCustom.setSourcead("test");
        perCustom.setSourcenote("test");

        userService.insertIntoPer(perCustom);
    }

    //文件上传测试
    @Test
    public void fileUpload()throws Exception{

        File file = new java.io.File("E:\\test11.txt");
        if(!file.exists()){
            file.mkdirs();
        }
    }
    @Test
    public void test()throws Exception{

        System.out.println("123");
    }


}
